package com.example.administrator.commonlyused;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.bigkoo.pickerview.TimePickerView;
import com.example.administrator.commonlyused.util.DateUtils;

import java.util.Calendar;
import java.util.Date;

public class TimeSelectionActivity extends AppCompatActivity implements View.OnClickListener {
    private TimePickerView pvTime;
    private TimePickerView endPvTime;
    String startTime;
    String endTime;
    /**
     * 时间选择
     */
    private Button mTimeSelection;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_time_selection);
        initView();
        initStartTimePickerView();
    }

    //初始化开始时间选择器
    private void initStartTimePickerView() {

        Calendar selectedDate = Calendar.getInstance();
        Calendar startDate = Calendar.getInstance();
        startDate.set(2017, 0, 01);
        Calendar endDate = Calendar.getInstance();
        endDate.set(2027, 11, 31);
        //时间选择器
        pvTime = new TimePickerView.Builder(this, new TimePickerView.OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {//选中事件回调

                Log.e("时间", DateUtils.formatDateCustom(date, "yyyy-MM-dd"));
                startTime = DateUtils.formatDateCustom(date, "yyyy-MM-dd");
                mTimeSelection.setText(startTime);
            }
        })
                //年月日时分秒 的显示与否，不设置则默认全部显示
                .setType(new boolean[]{true, true, true, false, false, false})
                .setLabel("", "", "", "", "", "")
                .isCenterLabel(false)
                .setDividerColor(Color.DKGRAY)
                .setContentSize(18)
                .setDate(selectedDate)
                .setRangDate(startDate, endDate)
                .setBackgroundId(0x00FFFFFF) //设置外部遮罩颜色
                .setDecorView(null)
                .setCancelText("取消")
                .setSubmitText("确认")
                .setSubCalSize(15)
                .setSubmitColor(Color.parseColor("#ffc107"))
                .setCancelColor(Color.parseColor("#ffc107"))
                .setTitleSize(16)
                .setTitleText("开始时间")
                .setTitleColor(Color.WHITE)
//                .setDividerColor(Color.WHITE)//设置分割线的颜色
                .setTextColorCenter(Color.WHITE)//设置选中项的颜色
                .setTextColorOut(Color.parseColor("#1e1e1e"))
//                .setLineSpacingMultiplier(1.6f)//设置两横线之间的间隔倍数
                .setTitleBgColor(Color.parseColor("#1e1e1e"))//标题背景颜色 Night mode
                .setBgColor(Color.parseColor("#363636"))//滚轮背景颜色 Night mode
                .build();
    }

    private void initView() {
        mTimeSelection = (Button) findViewById(R.id.timeSelection);
        mTimeSelection.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.timeSelection:
                pvTime.show();
                break;
        }
    }
}
